from .app import Flask
import os
import importlib

# 注册路由
def register_blueprints(app):
    # 将routes目录文件夹下的所有路由引入进去
    # 查找目录下面的所有文件名
    for value in os.listdir('./routes'):
        if os.path.splitext(value)[1] == ".py" and value != '__init__.py':
            model = importlib.import_module('routes.' + os.path.splitext(value)[0])
            app.register_blueprint(model.create_blueprint(), url_prefix= model.version)

# 注册数据库等插件
def register_plugin(app):
    # from libs.db.base import db
    # db.init_app(app)
    # with app.app_context():
    #     db.create_all()
    # 其他导入
    for value in os.listdir('./expand'):
        if os.path.splitext(value)[1] == ".py" and value != '__init__.py':
            model = importlib.import_module('expand.' + os.path.splitext(value)[0])
            model.expand(app)

# 入口文件
def create_app():
    # 使用封装的 Flask对象
    app = Flask(__name__)
    app.config.from_object('config.app')
    app.config.from_object('config.datebase')

   
    register_blueprints(app)
    register_plugin(app)
    return app

